//
//  NSString+WHSLocalizable.m
//  WHStudy
//
//  Created by GeDaTing on 2021/8/21.
//

#import "NSString+WHSLocalizable.h"
#import "NSBundle+WHSLocalizablePath.h"
#import "WHSLocalizableConfig.h"

@implementation NSString (WHSLocalizable)

+ (NSString *)whs_localizableWithKey:(NSString *)key
{
    NSBundle *bundle = [NSBundle whs_getLocalizableLprojBundle];
    if (bundle) {
        return NSLocalizedStringFromTableInBundle(key, nil, bundle, nil);
    }
    return nil;
}

+ (NSString *)whs_localizableWithCode:(NSInteger)code
{
    NSDictionary *dict = [WHSLocalizableConfig whs_getLocalizableCode];
    if (![dict isKindOfClass:NSDictionary.class]) {
        return nil;
    }
    NSDictionary *param = [dict objectForKey:[NSString stringWithFormat:@"%ld", code]];
    if (![param isKindOfClass:NSDictionary.class]) {
        return nil;
    }
    NSString *key = param[@"LocalizableKey"];
    if (![key isKindOfClass:NSString.class]) {
        return nil;
    }
    return [self whs_localizableWithKey:key];
}

@end
